
package cn.com.pusai.common.action;

import cn.com.pusai.core.util.StringUtil;
import com.opensymphony.xwork2.ActionInvocation;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;


public class GlobalReturnAction extends StrutsResultSupport
{

	private static final long serialVersionUID = 0x341d63bd1b473ba7L;

	public GlobalReturnAction()
	{
	}

	protected void doExecute(String arg, ActionInvocation invocation)
		throws Exception
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		String referer = ServletActionContext.getRequest().getHeader("referer");
		BaseAction action = (BaseAction)invocation.getAction();
		if (action.getWebInfo() != null)
		{
			if (StringUtil.isNotBlank(action.getWebInfo().getActionStatus()) || !action.getWebInfo().getInfoList().isEmpty() || !action.getWebInfo().getErrorList().isEmpty())
			{
				request.setAttribute("URL", referer);
				RequestDispatcher dispatcher = request.getRequestDispatcher(arg);
				dispatcher.forward(request, response);
			} else
			{
				response.sendRedirect(referer);
			}
		} else
		{
			response.sendRedirect(referer);
		}
	}
}
